import { Query } from '../../gis/utils/Query'
import { DOCNAME } from '../constants'

export const displayTra = function (map) {
  console.log(111)
  console.log(map)
  let roadFlow = [
    { where: ' 车流量<=1300', color: '#4fd27d' },
    { where: '车流量>1300 and 车流量<=1500', color: '#ffd045' },
    { where: '车流量>1500 and 车流量<=1700', color: '#e80e0e' },
    { where: '车流量>1700 and 车流量<=2100', color: '#b50000' },
  ]
  let service = { docName: DOCNAME, layerId: 1 }
  roadFlow.map((item) => {
    Query.queryBySql({
      where: item.where,
      service,
      callback: (res) => getBack(res, item),
    })
    const getBack = (res) => {
      var format = new Zondy.Format.PolygonJSON()
      //将MapGIS要素JSON反序列化为ol.Feature类型数组
      var features = format.read(res)
      //实例化一个矢量图层drawLayerr用于高亮显示结果
      var drawSource = new ol.source.Vector({
        wrapX: false,
      })
      drawSource.addFeatures(features)
      var drawLayer = new ol.layer.Vector({
        source: drawSource,
        style: new ol.style.Style({
          //边线样式
          stroke: new ol.style.Stroke({
            color: item.color,
            width: 3,
          }),
        }),
      })
      map.addLayer(drawLayer)
    }
  })
  return displayTra
}
